package TestDemo.example.service.impl;

import TestDemo.example.mapper.ClazzMapper;
import TestDemo.example.pojo.Clazz;
import TestDemo.example.pojo.ClazzQueryParam;
import TestDemo.example.pojo.PageResult;
import TestDemo.example.service.ClazzService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Slf4j
@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    public PageResult getClazzParamList(ClazzQueryParam clazzQueryParam) {
        PageHelper.startPage(clazzQueryParam.getPage(), clazzQueryParam.getPageSize());
        Page clazzPage = (Page) clazzMapper.getClazzParamList(clazzQueryParam);
        return new PageResult(clazzPage.getTotal(), clazzPage.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        clazzMapper.deleteById(id);
    }

    @Override
    public void add(Clazz clazz) {
        clazzMapper.add(clazz);
    }


    @Override
    public Clazz getById(Integer id) {
        return clazzMapper.getById(id);
    }

    @Override
    public void update(Clazz clazz) {
        clazzMapper.update(clazz);
        log.info("更新班级成功");
    }

    @Override
    public ArrayList<Clazz> Clazzlist() {
        return clazzMapper.Clazzlist();
    }
}
